package com.css.zfzx.fxpg.common.utils;

import java.io.*;

/**
 * 文件转字节流
 *
 * @author leon
 * @date 2020/11/17 20:10
 */
public class FileToByteUtil {
    public static byte[] fileToByte(String path) throws IOException {
        //创建字节对象
        byte[] buffer;
        File file = new File(path);
        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(fis.available());
        byte[] bytes = new byte[fis.available()];
        int temp;
        while ((temp = fis.read(bytes)) != -1) {
            baos.write(bytes, 0, temp);
        }
        fis.close();
        baos.close();
        buffer = baos.toByteArray();
        return buffer;
    }

}
